package org.judo.generate.mvc;

public class ValuesParser implements Parser
{
	ViewResult viewResult;
	DatatableInfo dataTable;
	private String curStatement;
	
	
	public ValuesParser()
	{
	}
	
	public ViewResult getViewResult()
	{
		return viewResult;
	}

	public void setViewResult(ViewResult viewResult)
	{
		this.viewResult = viewResult;
	}
	
	public Parser getNestedParser()
	{
		return null;
	}

	public boolean isFinished()
	{
		if (curStatement != null)
			if (curStatement.equals("/values"))
				return true;
				
		return false;
	}

	public boolean needsNestedParser()
	{
		return false;
	}

	public void parseNextLine(String line) throws ParseException
	{
		curStatement = line;
		
		if (line.startsWith("/values"))
		{
			viewResult.html += "\t\t\t</tr>\n";
			viewResult.html += "\t\t\t</c:forEach>\n";
		}
		else if (line.startsWith("#"))
		{
		}
		else
		{
			viewResult.html += "\t\t\t\t<td>"+line+"</td>\n";
		}
	}

	public void setInitLine(String line) throws ParseException
	{
		viewResult.html += "\t\t\t<c:forEach var=\""+dataTable.var+"\" items=\"${"+dataTable.items+"}\">\n";
		viewResult.html += "\t\t\t<tr>\n";
	}

	public DatatableInfo getDataTable()
	{
		return dataTable;
	}

	public void setDataTable(DatatableInfo dataTable)
	{
		this.dataTable = dataTable;
	}

}
